import type { ActionWithPayload } from "redux"
import { RESET, SETACTIVE, SETTABBARVISIBILITY } from "../actionTypes/tabbar"

/** helper for generate initial state for store */
function getInitialState(): ITabbarStore {
  return {
    tabBar: {
      custom: true,
      color: "#999999",
      selectedColor: "#5278FD",
      backgroundColor: "#FFFFFF",
      list: [
        {
          pagePath: "pages/tabbar/index/index",
          text: "首页",
          iconPath: "/images/yikao-community/tabbar-icon-index.png",
          selectedIconPath: "/images/yikao-community/tabbar-icon-index-selected.png"
        },
        {
          pagePath: "pages/tabbar/community/index",
          text: "社区",
          iconPath: "/images/yikao-community/tabbar-icon-community.png",
          selectedIconPath: "/images/yikao-community/tabbar-icon-community-selected.png"
        },
        {
          pagePath: "pages/tabbar/institution/index",
          text: "机构",
          iconPath: "/images/yikao-community/tabbar-icon-inst.png",
          selectedIconPath: "/images/yikao-community/tabbar-icon-inst-selected.png"
        },
        {
          pagePath: "pages/tabbar/me/index",
          text: "我的",
          iconPath: "/images/yikao-community/tabbar-icon-me.png",
          selectedIconPath: "/images/yikao-community/tabbar-icon-me-selected.png"
        }
      ],
      borderStyle: "black",
      position: "bottom"
    },
    appear: true,
    current: null
  }
}

/**
 * redux tabbar store
 * @param {ITabbarStore} state tabbar store state
 * @param {Action} action action
 * @returns tabbar store
 */
export default function (state = getInitialState(), action: ActionWithPayload): ITabbarStore {
  switch (action.type) {
    case RESET:
      return getInitialState()
    case SETACTIVE:
      return {
        ...state,
        current: action.payload
      }
    case SETTABBARVISIBILITY:
      return {
        ...state,
        appear: action.payload
      }
    default:
      return state
  }
}
